<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button icon="el-icon-plus" plain size="mini" type="primary" @click="handleAdd">
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button :disabled="single" icon="el-icon-edit" plain size="mini" type="success" @click="handleUpdate">
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button :disabled="multiple" icon="el-icon-delete" plain size="mini" type="danger" @click="handleDelete">
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-download" plain size="mini" type="warning" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
        <el-form-item label="到期时间" prop="jhEnddate">
          <el-date-picker v-model="queryParams.jhEnddate" end-placeholder="结束日期" range-separator="-" start-placeholder="开始日期" style="width: 240px" type="daterange"
                          value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-row>

    <el-table v-loading="loading" :data="accountList" border max-height="200" width="200" @selection-change="handleSelectionChange">
      <el-table-column align="center" label="天猫账号" prop="jhAccount"/>
      <el-table-column align="center" label="店铺名称" prop="jhName"/>
      <el-table-column align="center" label="会员身份" prop="jhIdentity"/>
      <el-table-column align="center" label="到期时间" prop="jhEnddate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jhEnddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="授权状态" prop="jhStatus"/>
      <el-table-column align="center" label="加油包" prop="jhTrafficNum"/>
      <el-table-column align="center" label="每日复制数量" prop="jhCopyNum"/>
      <el-table-column align="center" label="登录时间" prop="jhLoginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jhLoginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
                @pagination="getList"/>


  </div>
</template>

<script>
import {listAccount} from "@/api/jihuo/account";

export default {
  name: "Account",
  dicts: ['jh_listing_set', 'jh_repeat_set'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 天猫账户表格数据
      accountList: [],
      // 弹出层标题
      title: "",
      // 转移流量的原始账号id todo 应该将其设置为局部变量，而不是全局变量
      originalId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        beginJhEnddate: null,
        endJhEnddate: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询天猫账户列表 */
    getList() {
      this.loading = true;
      // todo 不知道怎么映射get的数组，同时查询条件还不会消失，暂时这样解决
      this.queryParams.beginJhEnddate = this.queryParams.jhEnddate ? this.queryParams.jhEnddate[0] : null;
      this.queryParams.endJhEnddate = this.queryParams.jhEnddate ? this.queryParams.jhEnddate[1] : null;
      this.queryParams.jhEnddate = null;
      listAccount(this.queryParams).then(response => {
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.queryParams.jhEnddate = [];
        this.queryParams.jhEnddate[0] = this.queryParams.beginJhEnddate ? this.queryParams.beginJhEnddate : null;
        this.queryParams.jhEnddate[1] = this.queryParams.endJhEnddate ? this.queryParams.endJhEnddate : null;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.config = false;
      this.transfer = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jhId: null,
        jhRevision: null,
        jhCreatedBy: null,
        jhCreatedTime: null,
        jhUpdatedBy: null,
        jhUpdatedTime: null,
        jhAccount: null,
        jhPassword: null,
        jhName: null,
        jhIdentity: null,
        jhEnddate: null,
        jhStatus: null,
        jhTrafficNum: null,
        jhCopyNum: null,
        jhLoginTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jihuo/account/export', {
        ...this.queryParams
      }, `account_${new Date().getTime()}.xlsx`)
    },
    openPage(href) {
      this.$router.push({path: href});
    },
    goTarget(href) {
      window.open(href, "_blank");
    }
  }
};
</script>
